#include <stdio.h>

template <typename T> 
class auto_ptr {
public:
    auto_ptr(T* p=nullptr): ptr(p) {}
    T& operator* () const {return *ptr;}
    T* operator-> () const {return ptr;} //注意自动重复使用"->"运算符
        //ap->x ==> (ap.operator->())->x ==> ptr->x
    //++pre, 前置++重载, 返回自增后的引用
    auto_ptr& operator++() {
        //根据容器类型调整底层指针
        //链表指针: ptr = ptr->next; 
        //如果为数组/向量：
        ptr++;
        return *this;
        
    }
    //post++, 后置++重载, 返回自增前的值
    auto_ptr operator++(int) {
        auto_ptr tmp = *this;
        ++*this;
        return tmp;
    }
private:
    T *ptr;    
};


int main(void) {
    typedef struct {
        int a;
        int b;
    }I2;
    I2 a[] = {{1, 2}, {3, 4}, {5, 6}};
    auto_ptr<I2> ap(a);
    printf("(*ap).a: %d\n", (*ap).a);
    printf("ap++ ->a :%d\n", ap++ -> a);
    auto_ptr<I2> &apr =  ++ap;
    printf("apr->b:%d\n", apr->b);
    printf("ap->b:%d\n", ap->b);
    return 0;
}
